{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-08-27T22:46:06.273926Z",
     "start_time": "2018-08-27T22:46:06.045988Z"
    }
   },
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "from tqdm import tqdm\n",
    "from IPython.display import display\n",
    "pd.set_option('display.max_columns', 99)\n",
    "pd.set_option('display.max_rows', 50)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-08-27T22:46:12.770567Z",
     "start_time": "2018-08-27T22:46:06.275450Z"
    }
   },
   "outputs": [],
   "source": [
    "train  = pd.read_csv('../input/application_train.csv.zip')\n",
    "train['is_train'] = 1\n",
    "\n",
    "test  = pd.read_csv('../input/application_test.csv.zip')\n",
    "test['is_train'] = 0\n",
    "\n",
    "trte = pd.concat([train, test], ignore_index=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-08-27T22:46:24.201902Z",
     "start_time": "2018-08-27T22:46:12.772439Z"
    }
   },
   "outputs": [],
   "source": [
    "prev = pd.read_csv('../input/previous_application.csv.zip')\n",
    "prev.sort_values('DAYS_DECISION', inplace=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-08-27T22:46:24.411683Z",
     "start_time": "2018-08-27T22:46:24.203828Z"
    }
   },
   "outputs": [],
   "source": [
    "user_id = pd.read_csv('../data/user_id_v4.csv.zip')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-08-27T22:46:25.960688Z",
     "start_time": "2018-08-27T22:46:24.413514Z"
    }
   },
   "outputs": [],
   "source": [
    "dup = user_id[user_id.duplicated('user_id', False)]\n",
    "cnt = dup.groupby('user_id').size()\n",
    "cnt.name = 'dup_cnt'\n",
    "cnt = cnt.reset_index()\n",
    "cnt['dup_id'] = range(cnt.shape[0])\n",
    "\n",
    "dup = pd.merge(dup, cnt, on='user_id', how='left')\n",
    "dup = pd.merge(dup, trte, on='SK_ID_CURR', how='left')\n",
    "dup.sort_values(['user_id', 'DAYS_BIRTH'], ascending=[True, False], inplace=True)\n",
    "\n",
    "dup['seq'] = 1\n",
    "dup['seq'] = dup.groupby('user_id').seq.cumsum()-1\n",
    "\n",
    "col = train.columns.tolist() + [c for c in dup.columns if c not in train.columns]\n",
    "for c in ['dup_id', 'dup_cnt', 'user_id']:\n",
    "    col.remove(c)\n",
    "col = ['user_id'] + col\n",
    "\n",
    "dup = dup[col]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-08-27T23:29:42.055148Z",
     "start_time": "2018-08-27T23:29:42.017439Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>user_id</th>\n",
       "      <th>SK_ID_CURR</th>\n",
       "      <th>TARGET</th>\n",
       "      <th>is_train</th>\n",
       "      <th>DAYS_BIRTH</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2</td>\n",
       "      <td>100041</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1</td>\n",
       "      <td>-12158</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3012</th>\n",
       "      <td>2</td>\n",
       "      <td>181102</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1</td>\n",
       "      <td>-12395</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2605</th>\n",
       "      <td>3</td>\n",
       "      <td>170362</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1</td>\n",
       "      <td>-17166</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>3</td>\n",
       "      <td>100043</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1</td>\n",
       "      <td>-17199</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2144</th>\n",
       "      <td>4</td>\n",
       "      <td>157771</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1</td>\n",
       "      <td>-12435</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>4</td>\n",
       "      <td>100066</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0</td>\n",
       "      <td>-12744</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11604</th>\n",
       "      <td>5</td>\n",
       "      <td>417707</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1</td>\n",
       "      <td>-7783</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>5</td>\n",
       "      <td>100072</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1</td>\n",
       "      <td>-7907</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12375</th>\n",
       "      <td>6</td>\n",
       "      <td>437195</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1</td>\n",
       "      <td>-15292</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>6</td>\n",
       "      <td>100090</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0</td>\n",
       "      <td>-15524</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>7</td>\n",
       "      <td>100094</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1</td>\n",
       "      <td>-22935</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2847</th>\n",
       "      <td>7</td>\n",
       "      <td>176665</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1</td>\n",
       "      <td>-23107</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>8</td>\n",
       "      <td>100125</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1</td>\n",
       "      <td>-21613</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9189</th>\n",
       "      <td>8</td>\n",
       "      <td>351641</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0</td>\n",
       "      <td>-21880</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10971</th>\n",
       "      <td>9</td>\n",
       "      <td>398229</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1</td>\n",
       "      <td>-16659</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>9</td>\n",
       "      <td>100144</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1</td>\n",
       "      <td>-16759</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>10</td>\n",
       "      <td>100147</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1</td>\n",
       "      <td>-16142</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9407</th>\n",
       "      <td>10</td>\n",
       "      <td>357498</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1</td>\n",
       "      <td>-16397</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1221</th>\n",
       "      <td>11</td>\n",
       "      <td>134172</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1</td>\n",
       "      <td>-16091</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>11</td>\n",
       "      <td>100164</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1</td>\n",
       "      <td>-16097</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>12</td>\n",
       "      <td>100190</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1</td>\n",
       "      <td>-13972</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2674</th>\n",
       "      <td>12</td>\n",
       "      <td>171997</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0</td>\n",
       "      <td>-14258</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9875</th>\n",
       "      <td>13</td>\n",
       "      <td>369392</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1</td>\n",
       "      <td>-14128</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>13</td>\n",
       "      <td>100232</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0</td>\n",
       "      <td>-14445</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4644</th>\n",
       "      <td>14</td>\n",
       "      <td>226916</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1</td>\n",
       "      <td>-20420</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12550</th>\n",
       "      <td>6490</td>\n",
       "      <td>442067</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0</td>\n",
       "      <td>-15060</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12556</th>\n",
       "      <td>6491</td>\n",
       "      <td>442215</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1</td>\n",
       "      <td>-19584</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12661</th>\n",
       "      <td>6491</td>\n",
       "      <td>445172</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1</td>\n",
       "      <td>-19584</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12618</th>\n",
       "      <td>6492</td>\n",
       "      <td>444203</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1</td>\n",
       "      <td>-24566</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12575</th>\n",
       "      <td>6492</td>\n",
       "      <td>442727</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1</td>\n",
       "      <td>-24568</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12586</th>\n",
       "      <td>6493</td>\n",
       "      <td>443146</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1</td>\n",
       "      <td>-10590</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13021</th>\n",
       "      <td>6493</td>\n",
       "      <td>454722</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0</td>\n",
       "      <td>-10751</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12611</th>\n",
       "      <td>6494</td>\n",
       "      <td>444049</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1</td>\n",
       "      <td>-11085</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12767</th>\n",
       "      <td>6494</td>\n",
       "      <td>447578</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1</td>\n",
       "      <td>-11204</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12679</th>\n",
       "      <td>6495</td>\n",
       "      <td>445498</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1</td>\n",
       "      <td>-10990</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12839</th>\n",
       "      <td>6495</td>\n",
       "      <td>449636</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0</td>\n",
       "      <td>-11110</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12862</th>\n",
       "      <td>6496</td>\n",
       "      <td>450293</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1</td>\n",
       "      <td>-18372</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12741</th>\n",
       "      <td>6496</td>\n",
       "      <td>446877</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0</td>\n",
       "      <td>-18567</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12747</th>\n",
       "      <td>6497</td>\n",
       "      <td>447028</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1</td>\n",
       "      <td>-13988</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12942</th>\n",
       "      <td>6497</td>\n",
       "      <td>452486</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1</td>\n",
       "      <td>-13988</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12813</th>\n",
       "      <td>6498</td>\n",
       "      <td>448823</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1</td>\n",
       "      <td>-17711</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12869</th>\n",
       "      <td>6498</td>\n",
       "      <td>450499</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1</td>\n",
       "      <td>-17823</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12838</th>\n",
       "      <td>6499</td>\n",
       "      <td>449596</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1</td>\n",
       "      <td>-14502</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13076</th>\n",
       "      <td>6499</td>\n",
       "      <td>456213</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1</td>\n",
       "      <td>-14589</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12898</th>\n",
       "      <td>6500</td>\n",
       "      <td>451376</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1</td>\n",
       "      <td>-16261</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12893</th>\n",
       "      <td>6500</td>\n",
       "      <td>451240</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1</td>\n",
       "      <td>-16431</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12911</th>\n",
       "      <td>6501</td>\n",
       "      <td>451723</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1</td>\n",
       "      <td>-11097</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12906</th>\n",
       "      <td>6501</td>\n",
       "      <td>451583</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1</td>\n",
       "      <td>-11338</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12925</th>\n",
       "      <td>6502</td>\n",
       "      <td>452030</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1</td>\n",
       "      <td>-19393</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13037</th>\n",
       "      <td>6502</td>\n",
       "      <td>455255</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0</td>\n",
       "      <td>-19661</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>13079 rows × 5 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "       user_id  SK_ID_CURR  TARGET  is_train  DAYS_BIRTH\n",
       "0            2      100041     0.0         1      -12158\n",
       "3012         2      181102     0.0         1      -12395\n",
       "2605         3      170362     0.0         1      -17166\n",
       "1            3      100043     0.0         1      -17199\n",
       "2144         4      157771     0.0         1      -12435\n",
       "2            4      100066     NaN         0      -12744\n",
       "11604        5      417707     0.0         1       -7783\n",
       "3            5      100072     0.0         1       -7907\n",
       "12375        6      437195     0.0         1      -15292\n",
       "4            6      100090     NaN         0      -15524\n",
       "5            7      100094     0.0         1      -22935\n",
       "2847         7      176665     0.0         1      -23107\n",
       "6            8      100125     0.0         1      -21613\n",
       "9189         8      351641     NaN         0      -21880\n",
       "10971        9      398229     0.0         1      -16659\n",
       "7            9      100144     0.0         1      -16759\n",
       "8           10      100147     0.0         1      -16142\n",
       "9407        10      357498     0.0         1      -16397\n",
       "1221        11      134172     0.0         1      -16091\n",
       "9           11      100164     0.0         1      -16097\n",
       "10          12      100190     0.0         1      -13972\n",
       "2674        12      171997     NaN         0      -14258\n",
       "9875        13      369392     0.0         1      -14128\n",
       "11          13      100232     NaN         0      -14445\n",
       "4644        14      226916     1.0         1      -20420\n",
       "...        ...         ...     ...       ...         ...\n",
       "12550     6490      442067     NaN         0      -15060\n",
       "12556     6491      442215     0.0         1      -19584\n",
       "12661     6491      445172     0.0         1      -19584\n",
       "12618     6492      444203     0.0         1      -24566\n",
       "12575     6492      442727     0.0         1      -24568\n",
       "12586     6493      443146     0.0         1      -10590\n",
       "13021     6493      454722     NaN         0      -10751\n",
       "12611     6494      444049     0.0         1      -11085\n",
       "12767     6494      447578     0.0         1      -11204\n",
       "12679     6495      445498     0.0         1      -10990\n",
       "12839     6495      449636     NaN         0      -11110\n",
       "12862     6496      450293     0.0         1      -18372\n",
       "12741     6496      446877     NaN         0      -18567\n",
       "12747     6497      447028     0.0         1      -13988\n",
       "12942     6497      452486     0.0         1      -13988\n",
       "12813     6498      448823     0.0         1      -17711\n",
       "12869     6498      450499     0.0         1      -17823\n",
       "12838     6499      449596     0.0         1      -14502\n",
       "13076     6499      456213     0.0         1      -14589\n",
       "12898     6500      451376     0.0         1      -16261\n",
       "12893     6500      451240     0.0         1      -16431\n",
       "12911     6501      451723     0.0         1      -11097\n",
       "12906     6501      451583     1.0         1      -11338\n",
       "12925     6502      452030     0.0         1      -19393\n",
       "13037     6502      455255     NaN         0      -19661\n",
       "\n",
       "[13079 rows x 5 columns]"
      ]
     },
     "execution_count": 36,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dup[['user_id', 'SK_ID_CURR', 'TARGET', 'is_train', 'DAYS_BIRTH']]#.to_csv('dup_tbl.csv', index=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-08-27T23:26:47.562257Z",
     "start_time": "2018-08-27T23:26:46.477181Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0          NaN\n",
       "3012       NaN\n",
       "2605    -237.0\n",
       "1       -237.0\n",
       "2144       NaN\n",
       "2          NaN\n",
       "11604    -33.0\n",
       "3        -33.0\n",
       "12375      NaN\n",
       "4          NaN\n",
       "5       -309.0\n",
       "2847    -309.0\n",
       "6          NaN\n",
       "9189       NaN\n",
       "10971   -124.0\n",
       "7       -124.0\n",
       "8          NaN\n",
       "9407       NaN\n",
       "1221    -232.0\n",
       "9       -232.0\n",
       "10         NaN\n",
       "2674       NaN\n",
       "9875    -172.0\n",
       "11      -172.0\n",
       "4644       NaN\n",
       "         ...  \n",
       "12550    -79.0\n",
       "12556      NaN\n",
       "12661      NaN\n",
       "12618      0.0\n",
       "12575      0.0\n",
       "12586      NaN\n",
       "13021      NaN\n",
       "12611      0.0\n",
       "12767      0.0\n",
       "12679      NaN\n",
       "12839      NaN\n",
       "12862      0.0\n",
       "12741      0.0\n",
       "12747      NaN\n",
       "12942      NaN\n",
       "12813   -120.0\n",
       "12869   -120.0\n",
       "12838      NaN\n",
       "13076      NaN\n",
       "12898   -224.0\n",
       "12893   -224.0\n",
       "12911      NaN\n",
       "12906      NaN\n",
       "12925     -1.0\n",
       "13037     -1.0\n",
       "Name: DAYS_BIRTH, Length: 13079, dtype: float64"
      ]
     },
     "execution_count": 34,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dup.groupby('user_id')['DAYS_BIRTH'].transform('diff')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-08-27T22:49:26.323088Z",
     "start_time": "2018-08-27T22:49:26.236125Z"
    }
   },
   "outputs": [],
   "source": [
    "sub_best = pd.read_csv('../data/stochastic_blending_v3-3_0.411rk7_0.304mw1_0.285t1_0.81031CV_0.3Adv.csv')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-08-27T22:57:05.814425Z",
     "start_time": "2018-08-27T22:57:05.746983Z"
    }
   },
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/home/Kazuki/anaconda3/lib/python3.6/site-packages/ipykernel_launcher.py:2: UserWarning: Boolean Series key will be reindexed to match DataFrame index.\n",
      "  \n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>SK_ID_CURR</th>\n",
       "      <th>TARGET</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>36</th>\n",
       "      <td>100271</td>\n",
       "      <td>0.156819</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>452</th>\n",
       "      <td>103171</td>\n",
       "      <td>0.764340</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1140</th>\n",
       "      <td>108045</td>\n",
       "      <td>0.986070</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2470</th>\n",
       "      <td>117249</td>\n",
       "      <td>0.898757</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2711</th>\n",
       "      <td>119014</td>\n",
       "      <td>0.614188</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2828</th>\n",
       "      <td>119813</td>\n",
       "      <td>0.975751</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2901</th>\n",
       "      <td>120388</td>\n",
       "      <td>0.172719</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4304</th>\n",
       "      <td>130774</td>\n",
       "      <td>0.613737</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4782</th>\n",
       "      <td>134494</td>\n",
       "      <td>0.973248</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5165</th>\n",
       "      <td>137651</td>\n",
       "      <td>0.897936</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5602</th>\n",
       "      <td>140996</td>\n",
       "      <td>0.988101</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6165</th>\n",
       "      <td>145157</td>\n",
       "      <td>0.601756</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6874</th>\n",
       "      <td>150501</td>\n",
       "      <td>0.969330</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7218</th>\n",
       "      <td>152833</td>\n",
       "      <td>0.907804</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7582</th>\n",
       "      <td>155547</td>\n",
       "      <td>0.948445</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8060</th>\n",
       "      <td>159078</td>\n",
       "      <td>0.866650</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8465</th>\n",
       "      <td>161993</td>\n",
       "      <td>0.953451</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10435</th>\n",
       "      <td>175737</td>\n",
       "      <td>0.748523</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15172</th>\n",
       "      <td>209288</td>\n",
       "      <td>0.852166</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15804</th>\n",
       "      <td>213957</td>\n",
       "      <td>0.900993</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16898</th>\n",
       "      <td>222303</td>\n",
       "      <td>0.908625</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17189</th>\n",
       "      <td>224488</td>\n",
       "      <td>0.817003</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18030</th>\n",
       "      <td>230748</td>\n",
       "      <td>0.859757</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18379</th>\n",
       "      <td>233512</td>\n",
       "      <td>0.348351</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23199</th>\n",
       "      <td>268602</td>\n",
       "      <td>0.491609</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>26646</th>\n",
       "      <td>293996</td>\n",
       "      <td>0.997887</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>27257</th>\n",
       "      <td>298776</td>\n",
       "      <td>0.991855</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>27352</th>\n",
       "      <td>299501</td>\n",
       "      <td>0.913282</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>28899</th>\n",
       "      <td>310586</td>\n",
       "      <td>0.593673</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>28975</th>\n",
       "      <td>311157</td>\n",
       "      <td>0.651260</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>29786</th>\n",
       "      <td>316815</td>\n",
       "      <td>0.998318</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>29840</th>\n",
       "      <td>317227</td>\n",
       "      <td>0.989517</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>31771</th>\n",
       "      <td>331191</td>\n",
       "      <td>0.939603</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>32748</th>\n",
       "      <td>338581</td>\n",
       "      <td>0.955584</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>34922</th>\n",
       "      <td>355320</td>\n",
       "      <td>0.616301</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>35378</th>\n",
       "      <td>358955</td>\n",
       "      <td>0.252093</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>35928</th>\n",
       "      <td>362872</td>\n",
       "      <td>0.709646</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>37014</th>\n",
       "      <td>370844</td>\n",
       "      <td>0.767828</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>37026</th>\n",
       "      <td>370882</td>\n",
       "      <td>0.952876</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>38254</th>\n",
       "      <td>381121</td>\n",
       "      <td>0.990481</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>38289</th>\n",
       "      <td>381203</td>\n",
       "      <td>0.994543</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>40935</th>\n",
       "      <td>401230</td>\n",
       "      <td>0.965719</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>40947</th>\n",
       "      <td>401332</td>\n",
       "      <td>0.549750</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>41925</th>\n",
       "      <td>407091</td>\n",
       "      <td>0.860885</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>43810</th>\n",
       "      <td>419787</td>\n",
       "      <td>0.971525</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>44078</th>\n",
       "      <td>421998</td>\n",
       "      <td>0.782722</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>44239</th>\n",
       "      <td>423503</td>\n",
       "      <td>0.966437</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>44668</th>\n",
       "      <td>427067</td>\n",
       "      <td>0.782825</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>47216</th>\n",
       "      <td>445047</td>\n",
       "      <td>0.868722</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>47918</th>\n",
       "      <td>450141</td>\n",
       "      <td>0.979300</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>56 rows × 2 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "       SK_ID_CURR    TARGET\n",
       "36         100271  0.156819\n",
       "452        103171  0.764340\n",
       "1140       108045  0.986070\n",
       "2470       117249  0.898757\n",
       "2711       119014  0.614188\n",
       "2828       119813  0.975751\n",
       "2901       120388  0.172719\n",
       "4304       130774  0.613737\n",
       "4782       134494  0.973248\n",
       "5165       137651  0.897936\n",
       "5602       140996  0.988101\n",
       "6165       145157  0.601756\n",
       "6874       150501  0.969330\n",
       "7218       152833  0.907804\n",
       "7582       155547  0.948445\n",
       "8060       159078  0.866650\n",
       "8465       161993  0.953451\n",
       "10435      175737  0.748523\n",
       "15172      209288  0.852166\n",
       "15804      213957  0.900993\n",
       "16898      222303  0.908625\n",
       "17189      224488  0.817003\n",
       "18030      230748  0.859757\n",
       "18379      233512  0.348351\n",
       "23199      268602  0.491609\n",
       "...           ...       ...\n",
       "26646      293996  0.997887\n",
       "27257      298776  0.991855\n",
       "27352      299501  0.913282\n",
       "28899      310586  0.593673\n",
       "28975      311157  0.651260\n",
       "29786      316815  0.998318\n",
       "29840      317227  0.989517\n",
       "31771      331191  0.939603\n",
       "32748      338581  0.955584\n",
       "34922      355320  0.616301\n",
       "35378      358955  0.252093\n",
       "35928      362872  0.709646\n",
       "37014      370844  0.767828\n",
       "37026      370882  0.952876\n",
       "38254      381121  0.990481\n",
       "38289      381203  0.994543\n",
       "40935      401230  0.965719\n",
       "40947      401332  0.549750\n",
       "41925      407091  0.860885\n",
       "43810      419787  0.971525\n",
       "44078      421998  0.782722\n",
       "44239      423503  0.966437\n",
       "44668      427067  0.782825\n",
       "47216      445047  0.868722\n",
       "47918      450141  0.979300\n",
       "\n",
       "[56 rows x 2 columns]"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "tmp = dup[dup.TARGET==0].user_id\n",
    "tmp = dup[dup.user_id.isin(tmp)][dup.is_train==0].SK_ID_CURR\n",
    "\n",
    "sub_best[sub_best.SK_ID_CURR.isin( tmp )]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-08-27T23:04:32.811707Z",
     "start_time": "2018-08-27T23:04:32.797174Z"
    }
   },
   "outputs": [],
   "source": [
    "user_id_test = dup[dup.is_train==0].user_id\n",
    "dup_test = dup[dup.user_id.isin(user_id_test)]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-08-27T23:04:33.600209Z",
     "start_time": "2018-08-27T23:04:33.586857Z"
    }
   },
   "outputs": [],
   "source": [
    "user_id_test_t0 = dup_test[dup_test.TARGET==0].user_id\n",
    "user_id_test_t1 = dup_test[dup_test.TARGET==1].user_id\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-08-27T23:04:34.464655Z",
     "start_time": "2018-08-27T23:04:34.447846Z"
    }
   },
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/home/Kazuki/anaconda3/lib/python3.6/site-packages/ipykernel_launcher.py:1: UserWarning: Boolean Series key will be reindexed to match DataFrame index.\n",
      "  \"\"\"Entry point for launching an IPython kernel.\n",
      "/home/Kazuki/anaconda3/lib/python3.6/site-packages/ipykernel_launcher.py:2: UserWarning: Boolean Series key will be reindexed to match DataFrame index.\n",
      "  \n"
     ]
    }
   ],
   "source": [
    "ids_0 = dup[dup.user_id.isin(user_id_test_t0)][dup.is_train==0].SK_ID_CURR.tolist()\n",
    "ids_1 = dup[dup.user_id.isin(user_id_test_t1)][dup.is_train==0].SK_ID_CURR.tolist()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-08-27T23:04:53.961893Z",
     "start_time": "2018-08-27T23:04:53.956978Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(2443, 56)"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(ids_0), len(ids_1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-08-27T23:05:28.751516Z",
     "start_time": "2018-08-27T23:05:28.746425Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(1, {358955})"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len( set(ids_0) & set(ids_1) ), set(ids_0) & set(ids_1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-08-27T23:07:40.281772Z",
     "start_time": "2018-08-27T23:07:40.278459Z"
    }
   },
   "outputs": [],
   "source": [
    "# remove 358955# remove \n",
    "ids_0.remove(358955)\n",
    "ids_1.remove(358955)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Swap"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-08-27T23:08:44.206261Z",
     "start_time": "2018-08-27T23:08:44.166569Z"
    }
   },
   "outputs": [],
   "source": [
    "sub_best.sort_values('TARGET', inplace=True)\n",
    "\n",
    "sub_0 = sub_best[sub_best.SK_ID_CURR.isin(ids_0)].reset_index(drop=True)\n",
    "sub_1 = sub_best[sub_best.SK_ID_CURR.isin(ids_1)].reset_index(drop=True)\n",
    "sub_other = sub_best[~sub_best.SK_ID_CURR.isin(ids_0+ids_1)].reset_index(drop=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-08-27T23:08:52.527300Z",
     "start_time": "2018-08-27T23:08:52.507647Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>SK_ID_CURR</th>\n",
       "      <th>TARGET</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>331032</td>\n",
       "      <td>0.000739</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>234695</td>\n",
       "      <td>0.001108</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>126822</td>\n",
       "      <td>0.001251</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>177424</td>\n",
       "      <td>0.001539</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>197224</td>\n",
       "      <td>0.001600</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>442541</td>\n",
       "      <td>0.002380</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>251267</td>\n",
       "      <td>0.002503</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>443039</td>\n",
       "      <td>0.002872</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>336791</td>\n",
       "      <td>0.003303</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>124362</td>\n",
       "      <td>0.003344</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>335313</td>\n",
       "      <td>0.003467</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>229298</td>\n",
       "      <td>0.003734</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>415117</td>\n",
       "      <td>0.004206</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>268761</td>\n",
       "      <td>0.004965</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>416826</td>\n",
       "      <td>0.005190</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>237103</td>\n",
       "      <td>0.006032</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>308403</td>\n",
       "      <td>0.006114</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>215488</td>\n",
       "      <td>0.006606</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>325377</td>\n",
       "      <td>0.006626</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>215739</td>\n",
       "      <td>0.006667</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>219000</td>\n",
       "      <td>0.007221</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>21</th>\n",
       "      <td>369016</td>\n",
       "      <td>0.007734</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22</th>\n",
       "      <td>211150</td>\n",
       "      <td>0.008350</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23</th>\n",
       "      <td>256392</td>\n",
       "      <td>0.008432</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>24</th>\n",
       "      <td>421690</td>\n",
       "      <td>0.009211</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2417</th>\n",
       "      <td>181538</td>\n",
       "      <td>0.985147</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2418</th>\n",
       "      <td>344229</td>\n",
       "      <td>0.985332</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2419</th>\n",
       "      <td>259020</td>\n",
       "      <td>0.985537</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2420</th>\n",
       "      <td>311609</td>\n",
       "      <td>0.986275</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2421</th>\n",
       "      <td>126438</td>\n",
       "      <td>0.986973</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2422</th>\n",
       "      <td>272148</td>\n",
       "      <td>0.987239</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2423</th>\n",
       "      <td>116880</td>\n",
       "      <td>0.988019</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2424</th>\n",
       "      <td>105584</td>\n",
       "      <td>0.989024</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2425</th>\n",
       "      <td>242499</td>\n",
       "      <td>0.989476</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2426</th>\n",
       "      <td>169580</td>\n",
       "      <td>0.990604</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2427</th>\n",
       "      <td>296696</td>\n",
       "      <td>0.991219</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2428</th>\n",
       "      <td>321416</td>\n",
       "      <td>0.991650</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2429</th>\n",
       "      <td>423061</td>\n",
       "      <td>0.992184</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2430</th>\n",
       "      <td>178182</td>\n",
       "      <td>0.992532</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2431</th>\n",
       "      <td>318615</td>\n",
       "      <td>0.992984</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2432</th>\n",
       "      <td>372463</td>\n",
       "      <td>0.993189</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2433</th>\n",
       "      <td>381754</td>\n",
       "      <td>0.993743</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2434</th>\n",
       "      <td>258966</td>\n",
       "      <td>0.994625</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2435</th>\n",
       "      <td>266468</td>\n",
       "      <td>0.996533</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2436</th>\n",
       "      <td>447972</td>\n",
       "      <td>0.996800</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2437</th>\n",
       "      <td>431170</td>\n",
       "      <td>0.997046</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2438</th>\n",
       "      <td>141215</td>\n",
       "      <td>0.998605</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2439</th>\n",
       "      <td>378349</td>\n",
       "      <td>0.999241</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2440</th>\n",
       "      <td>145874</td>\n",
       "      <td>0.999467</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2441</th>\n",
       "      <td>239616</td>\n",
       "      <td>0.999508</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>2442 rows × 2 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "      SK_ID_CURR    TARGET\n",
       "0         331032  0.000739\n",
       "1         234695  0.001108\n",
       "2         126822  0.001251\n",
       "3         177424  0.001539\n",
       "4         197224  0.001600\n",
       "5         442541  0.002380\n",
       "6         251267  0.002503\n",
       "7         443039  0.002872\n",
       "8         336791  0.003303\n",
       "9         124362  0.003344\n",
       "10        335313  0.003467\n",
       "11        229298  0.003734\n",
       "12        415117  0.004206\n",
       "13        268761  0.004965\n",
       "14        416826  0.005190\n",
       "15        237103  0.006032\n",
       "16        308403  0.006114\n",
       "17        215488  0.006606\n",
       "18        325377  0.006626\n",
       "19        215739  0.006667\n",
       "20        219000  0.007221\n",
       "21        369016  0.007734\n",
       "22        211150  0.008350\n",
       "23        256392  0.008432\n",
       "24        421690  0.009211\n",
       "...          ...       ...\n",
       "2417      181538  0.985147\n",
       "2418      344229  0.985332\n",
       "2419      259020  0.985537\n",
       "2420      311609  0.986275\n",
       "2421      126438  0.986973\n",
       "2422      272148  0.987239\n",
       "2423      116880  0.988019\n",
       "2424      105584  0.989024\n",
       "2425      242499  0.989476\n",
       "2426      169580  0.990604\n",
       "2427      296696  0.991219\n",
       "2428      321416  0.991650\n",
       "2429      423061  0.992184\n",
       "2430      178182  0.992532\n",
       "2431      318615  0.992984\n",
       "2432      372463  0.993189\n",
       "2433      381754  0.993743\n",
       "2434      258966  0.994625\n",
       "2435      266468  0.996533\n",
       "2436      447972  0.996800\n",
       "2437      431170  0.997046\n",
       "2438      141215  0.998605\n",
       "2439      378349  0.999241\n",
       "2440      145874  0.999467\n",
       "2441      239616  0.999508\n",
       "\n",
       "[2442 rows x 2 columns]"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "sub_0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-08-27T23:09:04.218463Z",
     "start_time": "2018-08-27T23:09:04.196401Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>SK_ID_CURR</th>\n",
       "      <th>TARGET</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>100271</td>\n",
       "      <td>0.156819</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>120388</td>\n",
       "      <td>0.172719</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>233512</td>\n",
       "      <td>0.348351</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>268602</td>\n",
       "      <td>0.491609</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>288876</td>\n",
       "      <td>0.513232</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>401332</td>\n",
       "      <td>0.549750</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>310586</td>\n",
       "      <td>0.593673</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>145157</td>\n",
       "      <td>0.601756</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>130774</td>\n",
       "      <td>0.613737</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>119014</td>\n",
       "      <td>0.614188</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>355320</td>\n",
       "      <td>0.616301</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>311157</td>\n",
       "      <td>0.651260</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>362872</td>\n",
       "      <td>0.709646</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>175737</td>\n",
       "      <td>0.748523</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>103171</td>\n",
       "      <td>0.764340</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>370844</td>\n",
       "      <td>0.767828</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>421998</td>\n",
       "      <td>0.782722</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>427067</td>\n",
       "      <td>0.782825</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>279778</td>\n",
       "      <td>0.795872</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>224488</td>\n",
       "      <td>0.817003</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>209288</td>\n",
       "      <td>0.852166</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>21</th>\n",
       "      <td>230748</td>\n",
       "      <td>0.859757</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22</th>\n",
       "      <td>407091</td>\n",
       "      <td>0.860885</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23</th>\n",
       "      <td>159078</td>\n",
       "      <td>0.866650</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>24</th>\n",
       "      <td>445047</td>\n",
       "      <td>0.868722</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>30</th>\n",
       "      <td>299501</td>\n",
       "      <td>0.913282</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>31</th>\n",
       "      <td>281876</td>\n",
       "      <td>0.929981</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>32</th>\n",
       "      <td>331191</td>\n",
       "      <td>0.939603</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>33</th>\n",
       "      <td>155547</td>\n",
       "      <td>0.948445</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>34</th>\n",
       "      <td>370882</td>\n",
       "      <td>0.952876</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>35</th>\n",
       "      <td>161993</td>\n",
       "      <td>0.953451</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>36</th>\n",
       "      <td>338581</td>\n",
       "      <td>0.955584</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>37</th>\n",
       "      <td>282317</td>\n",
       "      <td>0.957985</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>38</th>\n",
       "      <td>401230</td>\n",
       "      <td>0.965719</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>39</th>\n",
       "      <td>423503</td>\n",
       "      <td>0.966437</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>40</th>\n",
       "      <td>150501</td>\n",
       "      <td>0.969330</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>41</th>\n",
       "      <td>419787</td>\n",
       "      <td>0.971525</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>42</th>\n",
       "      <td>134494</td>\n",
       "      <td>0.973248</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>43</th>\n",
       "      <td>119813</td>\n",
       "      <td>0.975751</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>44</th>\n",
       "      <td>450141</td>\n",
       "      <td>0.979300</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>45</th>\n",
       "      <td>108045</td>\n",
       "      <td>0.986070</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>46</th>\n",
       "      <td>140996</td>\n",
       "      <td>0.988101</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>47</th>\n",
       "      <td>317227</td>\n",
       "      <td>0.989517</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>48</th>\n",
       "      <td>381121</td>\n",
       "      <td>0.990481</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>49</th>\n",
       "      <td>298776</td>\n",
       "      <td>0.991855</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>50</th>\n",
       "      <td>273336</td>\n",
       "      <td>0.992799</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>51</th>\n",
       "      <td>381203</td>\n",
       "      <td>0.994543</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>52</th>\n",
       "      <td>293996</td>\n",
       "      <td>0.997887</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>53</th>\n",
       "      <td>316815</td>\n",
       "      <td>0.998318</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>54</th>\n",
       "      <td>288138</td>\n",
       "      <td>0.999979</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>55 rows × 2 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "    SK_ID_CURR    TARGET\n",
       "0       100271  0.156819\n",
       "1       120388  0.172719\n",
       "2       233512  0.348351\n",
       "3       268602  0.491609\n",
       "4       288876  0.513232\n",
       "5       401332  0.549750\n",
       "6       310586  0.593673\n",
       "7       145157  0.601756\n",
       "8       130774  0.613737\n",
       "9       119014  0.614188\n",
       "10      355320  0.616301\n",
       "11      311157  0.651260\n",
       "12      362872  0.709646\n",
       "13      175737  0.748523\n",
       "14      103171  0.764340\n",
       "15      370844  0.767828\n",
       "16      421998  0.782722\n",
       "17      427067  0.782825\n",
       "18      279778  0.795872\n",
       "19      224488  0.817003\n",
       "20      209288  0.852166\n",
       "21      230748  0.859757\n",
       "22      407091  0.860885\n",
       "23      159078  0.866650\n",
       "24      445047  0.868722\n",
       "..         ...       ...\n",
       "30      299501  0.913282\n",
       "31      281876  0.929981\n",
       "32      331191  0.939603\n",
       "33      155547  0.948445\n",
       "34      370882  0.952876\n",
       "35      161993  0.953451\n",
       "36      338581  0.955584\n",
       "37      282317  0.957985\n",
       "38      401230  0.965719\n",
       "39      423503  0.966437\n",
       "40      150501  0.969330\n",
       "41      419787  0.971525\n",
       "42      134494  0.973248\n",
       "43      119813  0.975751\n",
       "44      450141  0.979300\n",
       "45      108045  0.986070\n",
       "46      140996  0.988101\n",
       "47      317227  0.989517\n",
       "48      381121  0.990481\n",
       "49      298776  0.991855\n",
       "50      273336  0.992799\n",
       "51      381203  0.994543\n",
       "52      293996  0.997887\n",
       "53      316815  0.998318\n",
       "54      288138  0.999979\n",
       "\n",
       "[55 rows x 2 columns]"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "sub_1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-08-27T23:09:21.172398Z",
     "start_time": "2018-08-27T23:09:21.166739Z"
    }
   },
   "outputs": [],
   "source": [
    "target_all = sorted(sub_0.append(sub_1).TARGET.values)\n",
    "target_0, target_1 = target_all[:sub_0.shape[0]], target_all[sub_0.shape[0]:]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-08-27T23:09:33.241691Z",
     "start_time": "2018-08-27T23:09:33.237346Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(2442, 55)"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(target_0), len(target_1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-08-27T23:09:44.311030Z",
     "start_time": "2018-08-27T23:09:44.306744Z"
    }
   },
   "outputs": [],
   "source": [
    "sub_0.TARGET = target_0\n",
    "sub_1.TARGET = target_1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-08-27T23:09:56.502032Z",
     "start_time": "2018-08-27T23:09:56.466943Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>SK_ID_CURR</th>\n",
       "      <th>TARGET</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>331032</td>\n",
       "      <td>0.000739</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>234695</td>\n",
       "      <td>0.001108</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>126822</td>\n",
       "      <td>0.001251</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>177424</td>\n",
       "      <td>0.001539</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>197224</td>\n",
       "      <td>0.001600</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>442541</td>\n",
       "      <td>0.002380</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>251267</td>\n",
       "      <td>0.002503</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>443039</td>\n",
       "      <td>0.002872</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>336791</td>\n",
       "      <td>0.003303</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>124362</td>\n",
       "      <td>0.003344</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>335313</td>\n",
       "      <td>0.003467</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>229298</td>\n",
       "      <td>0.003734</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>415117</td>\n",
       "      <td>0.004206</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>268761</td>\n",
       "      <td>0.004965</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>416826</td>\n",
       "      <td>0.005190</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>237103</td>\n",
       "      <td>0.006032</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>308403</td>\n",
       "      <td>0.006114</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>215488</td>\n",
       "      <td>0.006606</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>325377</td>\n",
       "      <td>0.006626</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>215739</td>\n",
       "      <td>0.006667</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>219000</td>\n",
       "      <td>0.007221</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>21</th>\n",
       "      <td>369016</td>\n",
       "      <td>0.007734</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22</th>\n",
       "      <td>211150</td>\n",
       "      <td>0.008350</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23</th>\n",
       "      <td>256392</td>\n",
       "      <td>0.008432</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>24</th>\n",
       "      <td>421690</td>\n",
       "      <td>0.009211</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2417</th>\n",
       "      <td>181538</td>\n",
       "      <td>0.966786</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2418</th>\n",
       "      <td>344229</td>\n",
       "      <td>0.966929</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2419</th>\n",
       "      <td>259020</td>\n",
       "      <td>0.966970</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2420</th>\n",
       "      <td>311609</td>\n",
       "      <td>0.967258</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2421</th>\n",
       "      <td>126438</td>\n",
       "      <td>0.967299</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2422</th>\n",
       "      <td>272148</td>\n",
       "      <td>0.967606</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2423</th>\n",
       "      <td>116880</td>\n",
       "      <td>0.967709</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2424</th>\n",
       "      <td>105584</td>\n",
       "      <td>0.967996</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2425</th>\n",
       "      <td>242499</td>\n",
       "      <td>0.969309</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2426</th>\n",
       "      <td>169580</td>\n",
       "      <td>0.969330</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2427</th>\n",
       "      <td>296696</td>\n",
       "      <td>0.969453</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2428</th>\n",
       "      <td>321416</td>\n",
       "      <td>0.970130</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2429</th>\n",
       "      <td>423061</td>\n",
       "      <td>0.971299</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2430</th>\n",
       "      <td>178182</td>\n",
       "      <td>0.971525</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2431</th>\n",
       "      <td>318615</td>\n",
       "      <td>0.971853</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2432</th>\n",
       "      <td>372463</td>\n",
       "      <td>0.972058</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2433</th>\n",
       "      <td>381754</td>\n",
       "      <td>0.972140</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2434</th>\n",
       "      <td>258966</td>\n",
       "      <td>0.972509</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2435</th>\n",
       "      <td>266468</td>\n",
       "      <td>0.973145</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2436</th>\n",
       "      <td>447972</td>\n",
       "      <td>0.973248</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2437</th>\n",
       "      <td>431170</td>\n",
       "      <td>0.973310</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2438</th>\n",
       "      <td>141215</td>\n",
       "      <td>0.974212</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2439</th>\n",
       "      <td>378349</td>\n",
       "      <td>0.975197</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2440</th>\n",
       "      <td>145874</td>\n",
       "      <td>0.975279</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2441</th>\n",
       "      <td>239616</td>\n",
       "      <td>0.975464</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>2442 rows × 2 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "      SK_ID_CURR    TARGET\n",
       "0         331032  0.000739\n",
       "1         234695  0.001108\n",
       "2         126822  0.001251\n",
       "3         177424  0.001539\n",
       "4         197224  0.001600\n",
       "5         442541  0.002380\n",
       "6         251267  0.002503\n",
       "7         443039  0.002872\n",
       "8         336791  0.003303\n",
       "9         124362  0.003344\n",
       "10        335313  0.003467\n",
       "11        229298  0.003734\n",
       "12        415117  0.004206\n",
       "13        268761  0.004965\n",
       "14        416826  0.005190\n",
       "15        237103  0.006032\n",
       "16        308403  0.006114\n",
       "17        215488  0.006606\n",
       "18        325377  0.006626\n",
       "19        215739  0.006667\n",
       "20        219000  0.007221\n",
       "21        369016  0.007734\n",
       "22        211150  0.008350\n",
       "23        256392  0.008432\n",
       "24        421690  0.009211\n",
       "...          ...       ...\n",
       "2417      181538  0.966786\n",
       "2418      344229  0.966929\n",
       "2419      259020  0.966970\n",
       "2420      311609  0.967258\n",
       "2421      126438  0.967299\n",
       "2422      272148  0.967606\n",
       "2423      116880  0.967709\n",
       "2424      105584  0.967996\n",
       "2425      242499  0.969309\n",
       "2426      169580  0.969330\n",
       "2427      296696  0.969453\n",
       "2428      321416  0.970130\n",
       "2429      423061  0.971299\n",
       "2430      178182  0.971525\n",
       "2431      318615  0.971853\n",
       "2432      372463  0.972058\n",
       "2433      381754  0.972140\n",
       "2434      258966  0.972509\n",
       "2435      266468  0.973145\n",
       "2436      447972  0.973248\n",
       "2437      431170  0.973310\n",
       "2438      141215  0.974212\n",
       "2439      378349  0.975197\n",
       "2440      145874  0.975279\n",
       "2441      239616  0.975464\n",
       "\n",
       "[2442 rows x 2 columns]"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "sub_0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-08-27T23:10:07.345029Z",
     "start_time": "2018-08-27T23:10:07.326482Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>SK_ID_CURR</th>\n",
       "      <th>TARGET</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>100271</td>\n",
       "      <td>0.975628</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>120388</td>\n",
       "      <td>0.975751</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>233512</td>\n",
       "      <td>0.976120</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>268602</td>\n",
       "      <td>0.976879</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>288876</td>\n",
       "      <td>0.977002</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>401332</td>\n",
       "      <td>0.978685</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>310586</td>\n",
       "      <td>0.979259</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>145157</td>\n",
       "      <td>0.979300</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>130774</td>\n",
       "      <td>0.979649</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>119014</td>\n",
       "      <td>0.979874</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>355320</td>\n",
       "      <td>0.980387</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>311157</td>\n",
       "      <td>0.980716</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>362872</td>\n",
       "      <td>0.981187</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>175737</td>\n",
       "      <td>0.981311</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>103171</td>\n",
       "      <td>0.981331</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>370844</td>\n",
       "      <td>0.981618</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>421998</td>\n",
       "      <td>0.981885</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>427067</td>\n",
       "      <td>0.982152</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>279778</td>\n",
       "      <td>0.982377</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>224488</td>\n",
       "      <td>0.983054</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>209288</td>\n",
       "      <td>0.985147</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>21</th>\n",
       "      <td>230748</td>\n",
       "      <td>0.985332</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22</th>\n",
       "      <td>407091</td>\n",
       "      <td>0.985537</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23</th>\n",
       "      <td>159078</td>\n",
       "      <td>0.986070</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>24</th>\n",
       "      <td>445047</td>\n",
       "      <td>0.986275</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>30</th>\n",
       "      <td>299501</td>\n",
       "      <td>0.989476</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>31</th>\n",
       "      <td>281876</td>\n",
       "      <td>0.989517</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>32</th>\n",
       "      <td>331191</td>\n",
       "      <td>0.990481</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>33</th>\n",
       "      <td>155547</td>\n",
       "      <td>0.990604</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>34</th>\n",
       "      <td>370882</td>\n",
       "      <td>0.991219</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>35</th>\n",
       "      <td>161993</td>\n",
       "      <td>0.991650</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>36</th>\n",
       "      <td>338581</td>\n",
       "      <td>0.991855</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>37</th>\n",
       "      <td>282317</td>\n",
       "      <td>0.992184</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>38</th>\n",
       "      <td>401230</td>\n",
       "      <td>0.992532</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>39</th>\n",
       "      <td>423503</td>\n",
       "      <td>0.992799</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>40</th>\n",
       "      <td>150501</td>\n",
       "      <td>0.992984</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>41</th>\n",
       "      <td>419787</td>\n",
       "      <td>0.993189</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>42</th>\n",
       "      <td>134494</td>\n",
       "      <td>0.993743</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>43</th>\n",
       "      <td>119813</td>\n",
       "      <td>0.994543</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>44</th>\n",
       "      <td>450141</td>\n",
       "      <td>0.994625</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>45</th>\n",
       "      <td>108045</td>\n",
       "      <td>0.996533</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>46</th>\n",
       "      <td>140996</td>\n",
       "      <td>0.996800</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>47</th>\n",
       "      <td>317227</td>\n",
       "      <td>0.997046</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>48</th>\n",
       "      <td>381121</td>\n",
       "      <td>0.997887</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>49</th>\n",
       "      <td>298776</td>\n",
       "      <td>0.998318</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>50</th>\n",
       "      <td>273336</td>\n",
       "      <td>0.998605</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>51</th>\n",
       "      <td>381203</td>\n",
       "      <td>0.999241</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>52</th>\n",
       "      <td>293996</td>\n",
       "      <td>0.999467</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>53</th>\n",
       "      <td>316815</td>\n",
       "      <td>0.999508</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>54</th>\n",
       "      <td>288138</td>\n",
       "      <td>0.999979</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>55 rows × 2 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "    SK_ID_CURR    TARGET\n",
       "0       100271  0.975628\n",
       "1       120388  0.975751\n",
       "2       233512  0.976120\n",
       "3       268602  0.976879\n",
       "4       288876  0.977002\n",
       "5       401332  0.978685\n",
       "6       310586  0.979259\n",
       "7       145157  0.979300\n",
       "8       130774  0.979649\n",
       "9       119014  0.979874\n",
       "10      355320  0.980387\n",
       "11      311157  0.980716\n",
       "12      362872  0.981187\n",
       "13      175737  0.981311\n",
       "14      103171  0.981331\n",
       "15      370844  0.981618\n",
       "16      421998  0.981885\n",
       "17      427067  0.982152\n",
       "18      279778  0.982377\n",
       "19      224488  0.983054\n",
       "20      209288  0.985147\n",
       "21      230748  0.985332\n",
       "22      407091  0.985537\n",
       "23      159078  0.986070\n",
       "24      445047  0.986275\n",
       "..         ...       ...\n",
       "30      299501  0.989476\n",
       "31      281876  0.989517\n",
       "32      331191  0.990481\n",
       "33      155547  0.990604\n",
       "34      370882  0.991219\n",
       "35      161993  0.991650\n",
       "36      338581  0.991855\n",
       "37      282317  0.992184\n",
       "38      401230  0.992532\n",
       "39      423503  0.992799\n",
       "40      150501  0.992984\n",
       "41      419787  0.993189\n",
       "42      134494  0.993743\n",
       "43      119813  0.994543\n",
       "44      450141  0.994625\n",
       "45      108045  0.996533\n",
       "46      140996  0.996800\n",
       "47      317227  0.997046\n",
       "48      381121  0.997887\n",
       "49      298776  0.998318\n",
       "50      273336  0.998605\n",
       "51      381203  0.999241\n",
       "52      293996  0.999467\n",
       "53      316815  0.999508\n",
       "54      288138  0.999979\n",
       "\n",
       "[55 rows x 2 columns]"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "sub_1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-08-27T23:10:32.785639Z",
     "start_time": "2018-08-27T23:10:32.756962Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(48744, 2)"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "sub_new = pd.concat([sub_0, sub_1, sub_other])\n",
    "sub_new.sort_values('TARGET', inplace=True)\n",
    "sub_new.reset_index(drop=True, inplace=True)\n",
    "\n",
    "sub_new.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-08-27T23:10:58.943753Z",
     "start_time": "2018-08-27T23:10:58.936472Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "((48744, 2), (48744,))"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "sub_best.shape, sub_new.SK_ID_CURR.unique().shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-08-27T23:11:24.141181Z",
     "start_time": "2018-08-27T23:11:23.396850Z"
    }
   },
   "outputs": [],
   "source": [
    "sub_new.to_csv('../output/stochastic_blending_v3-2_0.308rk7_0.431mw1_0.261t1_0.81050CV_0.3Adv_Leak005.csv.gz', index=False, compression='gzip')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
